package com.emeraldparser.util;

import com.google.common.base.Objects;
import com.google.common.collect.Multiset;

public abstract class AbstractMultisetEntry<E> implements Multiset.Entry<E> {

	@Override
	public String toString() {
		return getElement() + " x " + getCount();
	}

	@Override
	public boolean equals(Object o) {
		if (o == this) {
			return true;
		}
		
		if (o == null) {
			return false;
		}
		
		if (!(o instanceof Multiset.Entry<?>)) {
			return false;
		}
		
		Multiset.Entry<?> other = (Multiset.Entry<?>) o;
		
		return Objects.equal(getElement(), other.getElement())
		    && getCount() == other.getCount();
	}

	@Override
	public int hashCode() {
		E element = getElement();
		int count = getCount();
		return ((element == null) ? 0 : element.hashCode()) ^ count;
	}

}
